package com.naiterui.ehp.bs.esign.repository.mysql;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.esign.entity.mysql.EsignPharmacist;

/**
 * @author guoyongxiang
 * @date 2019/12/2 10:56
 * @since 1.0.0
 */
@Repository
public interface IEsignRecomEsignPharmacistRepository extends BaseJpaRepository<EsignPharmacist, Long> {

    /**
     * 根据药师ID查询药师电子签名用户信息
     *
     * @param pharmacistId
     *
     * @return
     */
    EsignPharmacist findFirstByPharmacistId(Long pharmacistId);

    /**
     * 根据身份证号查询
     * @param idcar
     * @return
     */
    EsignPharmacist findFirstByIdCard(String idcar);

    /**
     * 根据签名平台用户ID查询签名用户信息
     *
     * @param openId
     *
     * @return
     */
    EsignPharmacist findFirstByOpenId(String openId);


    /**
     * 根据手机号查询
     *
     * @param phone
     *
     * @return
     */
    EsignPharmacist findFirstByPhone(String phone);

    EsignPharmacist findFirstByIdCardAndAuthStatus(String idCard, Integer authStatus);

    /**
     * 修改免密状态
     *
     * @param noSecret
     * @param authPwd
     * @param id
     */
    @Modifying
    @Query(
        value = "update recom_esign_pharmacist set no_secret = ?1, auth_pwd = ?2, changed_at=now(),changed_by='system' where id = ?3",
        nativeQuery = true)
    void updateNoSecretAuthPwd(Integer noSecret, String authPwd, Long id);
}
